package com.wxq.workpad.finishproduct.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.wxq.workpad.R
import com.wxq.workpad.entity.LaiLiaoItemEntity
import com.wxq.workpad.entity.ProductItemEntity

/**
 * @Description: 类作用描述
 */
class ProductListAdapter(context: Context):RecyclerView.Adapter<RecyclerView.ViewHolder>() {
    private var mContext:Context

    private var mData:MutableList<ProductItemEntity>

    private lateinit var listener:(position:Int)->Unit

    init {
        mContext=context
        mData= mutableListOf()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return ItemHold(LayoutInflater.from(mContext).inflate(R.layout.item_product,parent,false))
    }

    override fun getItemCount(): Int {
        if (mData==null){
            return 0;
        }
        return mData.size
    }

    fun updateDate(data:MutableList<ProductItemEntity>){
         mData=data
         notifyDataSetChanged()
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is ItemHold){
            val item = mData.get(position)

            holder.tv_test.setOnClickListener {
                listener(position)
            }

        }
    }




    fun setClickListener(itemClick:(position:Int)->Unit){
        listener=itemClick
    }


    inner class ItemHold(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var tv_test:TextView

        init {
            tv_test= itemView.findViewById(R.id.tv_test)

        }
    }
}